package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.AttributeEntity;
import com.example.demo.mapper.DsEntityMapper;
import com.example.demo.service.IDsEntityService;
import org.apache.commons.text.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 实体属性定义扩展 服务实现类
 * </p>
 *
 * @author dxd
 * @since 2020-09-03
 */
@Service
public class DsEntityServiceImpl extends ServiceImpl<DsEntityMapper, AttributeEntity> implements IDsEntityService {

    @Autowired
    DsEntityMapper mapper;

    @Override
    public void removeByBusi(String businessType) {
        mapper.deleteBybusinessType(businessType);
    }

    @Override
    public List<Map> listcolumns(String businessType) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.select("id", "prop_name", "prop_label", "prop_sort", "extensions", "is_visible", "nullable")
                .ge(true, "business_type", businessType);
        List<Map> m = mapper.selectMaps(wrapper);
        for (Map map : m) {
            map.put("extensions", StringEscapeUtils.unescapeJson((String) map.get("extensions")));
        }
        return m;
    }
}
